import tseslint from 'typescript-eslint'
import eslint from '@eslint/js'
import prettier from 'eslint-plugin-prettier'
import importSort from 'eslint-plugin-simple-import-sort'
import globals from 'globals'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'



const ignores =[
    'node_modules',
    'dist',
    'build',
    '**/*.mjs',
    '**/*.d.ts',
    'eslint.config.js',
    "commitlint.config.js"
]

const commonConfig = {
    ignores,
    extends:[eslint.configs.recommended, ...tseslint.configs.recommended],
    rules: {
        "no-console": "error",
        "prettier/prettier": "error",
        'simple-import-sort/imports': 'error',
        'simple-import-sort/exports': 'error',
    },
    plugins:{
        prettier,
        'simple-import-sort': importSort,
    }
}

const frontendConfig = {
    files:['apps/frontend/**/*.{ts,tsx}','packages/**/*.{ts,tsx}'],
    languageOptions: {
        ecmaVersion:2020,
        globals:globals.browser
    },
    plugins: {
        'react-hooks':reactHooks,
        'react-refresh':reactRefresh
    },
    rules: {
        ...reactHooks.configs.recommended.rules,
        'react-refresh/only-export-components': 'warn',
    }
}

const backendConfig = {
    languageOptions: {
        ecmaVersion:2020,
        globals:{
            ...globals.node
        },
        parser: tseslint.parser
    },
    rules: {
        '@typescript-eslint/explicit-function-return-type': 'off',
        '@typescript-eslint/explicit-module-boundary-types': 'off',
        '@typescript-eslint/interface-name-prefix': 'off',
        'no-explicit-any': 'off',
        '@typescript-eslint/no-explicit-any': 'off',
    }
}


export default tseslint.config(commonConfig,frontendConfig,backendConfig)